package com.fbinggun.fbinggunutil;

import org.bukkit.Bukkit;
import org.bukkit.Location;

/**
 * 坐标处理方法 常用与坐标转换字符串 或反转换
 */
@Deprecated
public class LocUtil {

    /**
     * 将字符串转为 坐标
     * @param str 坐标的字符串 格式：世界名,x,y,z,yew,pitch
     * @return
     */

    //将字符串转坐标
    public static Location getLocation(String str){
        String[] strings= str.split(",");
        String world = strings[0];
        double x =Double.valueOf(strings[1]);
        double y=Double.valueOf(strings[2]);
        double z=Double.valueOf(strings[3]);
        float yew = 0;
        float pitch=0;
        if(strings.length==6){
            yew = Float.valueOf(strings[4]);
            pitch=Float.valueOf(strings[5]);
        }
        return new Location(Bukkit.getWorld(world),x,y,z,yew,pitch);
    }

    /**
     * 将坐标转为 字符串
     * @param loc 坐标
     * @return 格式：世界名,x,y,z,yew,pitch
     */
    //将坐标转字符串
    public static String toLocation(Location loc){
        return loc.getWorld().getName()+","+loc.getX()+","+loc.getY()+","+loc.getZ()+","+loc.getYaw()+","+loc.getPitch();
    }
}
